package cn.edu.ljl.rest;

import cn.edu.ljl.Page;
import cn.edu.ljl.Student;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.Writer;
import java.sql.SQLException;
import java.util.List;

public class numbers extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        this.doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        String page = request.getParameter("page");
        int numbers;

        if(page.equals("1")){
            numbers=cn.edu.ljl.login.number;   //获取login.number作为数据，退出时修改的数据也会改变login.number

            Writer writer = response.getWriter();
            StringBuilder sb = new StringBuilder();

            sb.append(Page.getClearHeader());
            sb.append(toHtmlPic());
            sb.append(toHtml(numbers));
            sb.append(Page.getEnd());
            writer.write(sb.toString());
            }

    }

    private String toHtml(int numbers) {

        StringBuilder sb = new StringBuilder();
        sb.append("<center>");
        sb.append("<br><br><br>");
        sb.append("<font face=\"宋体\" size=\"6\" color=\"#003153\">当前在线人数是：</font>");
        sb.append("<font face=\"宋体\" size=\"6\" color=\"#003153\">"+numbers+"</font>");
        sb.append("</center>");
        return sb.toString();
    }

    private String toHtmlPic() {

        String pic =  "<style type=\"text/css\">\n" +
                "\tbody{\n" +
                "\t\tbackground: url(\"./pic/lu.jpg\") no-repeat center center fixed;\n" +
                "                /*兼容浏览器版本*/\n" +
                "                -webkit-background-size: cover;\n" +
                "                -o-background-size: cover;\n" +
                "                background-size: cover;\n" +
                "\t}\n" +
                "</style>";
        return pic;
    }
}
